package cc.rengu.igas.bomp.core.service.trans;

import cc.rengu.igas.bomp.common.dao.MchntBaseInfoMapper;
import cc.rengu.igas.bomp.common.dao.impl.MchntBaseInfoMapperImpl;
import cc.rengu.igas.bomp.common.entity.MchntBaseInfo;
import cc.rengu.igas.bomp.common.enums.RespCodeEnum;
import cc.rengu.igas.bomp.core.service.base.ManageService;
import cc.rengu.igas.bomp.facade.request.MchntBaseInfoSaveRequest;
import cc.rengu.igas.bomp.facade.request.MchntBaseInfoUpdateRequest;
import cc.rengu.igas.bomp.facade.response.MchntBaseInfoSaveResponse;
import cc.rengu.igas.bomp.facade.response.MchntBaseInfoUpdateResponse;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.utility.util.BeanUtil;
import cc.rengu.oltp.utility.util.ConvertUtil;

public class MchntBaseInfoSaveService extends ManageService {
    @Override
    protected Object bizBeforeCust() throws Exception {
        MchntBaseInfoSaveRequest mchntBaseInfoSaveRequest=new MchntBaseInfoSaveRequest();
        ConvertUtil.convertOutput(mchntBaseInfoSaveRequest);
        return mchntBaseInfoSaveRequest;
    }

    @Override
    protected BizResponse bizProcessCust(Object request) throws Exception {
        MchntBaseInfoSaveRequest mchntBaseInfoSaveRequest = (MchntBaseInfoSaveRequest) request;
        MchntBaseInfoMapper mchntBaseInfoMapper = new MchntBaseInfoMapperImpl();
        BizResponse bizResponse = new BizResponse();
        MchntBaseInfoSaveResponse response = new MchntBaseInfoSaveResponse();
        String id = mchntBaseInfoSaveRequest.getId();
        String mchntType = mchntBaseInfoSaveRequest.getMchntType();
        String mchntNo = mchntBaseInfoSaveRequest.getMchntNo();
        String mchntName = mchntBaseInfoSaveRequest.getMchntName();
        String mchntSimpleName = mchntBaseInfoSaveRequest.getMchntSimpleName();
        String mchntBizAddr = mchntBaseInfoSaveRequest.getMchntBizAddr();
        String mchntNature = mchntBaseInfoSaveRequest.getMchntNature();
        String managementScope = mchntBaseInfoSaveRequest.getManagementScope();
        String industryType = mchntBaseInfoSaveRequest.getIndustryType();
        String signInstId = mchntBaseInfoSaveRequest.getSignInstId();
        String mchntLevel = mchntBaseInfoSaveRequest.getMchntLevel();
        response.setHeader(mchntBaseInfoSaveRequest.getHeader());
        if (null != id && !id.isEmpty()
        ){
            MchntBaseInfo mchntBaseInfo=new MchntBaseInfo();
            BeanUtil.beanCopy(mchntBaseInfoSaveRequest,mchntBaseInfo);
            int i = mchntBaseInfoMapper.updateMchntBaseInfoById(mchntBaseInfo);
            if (i==0){
                response.setMsg("商户信息更新成功");
                bizResponse.setResult(response);
                bizResponse.setRspSysId(AppParamConstant.SYS_ID);
                bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
                bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
                return bizResponse;
            }
            response.setMsg("商户信息更新失败");
            bizResponse.setResult(response);
            bizResponse.setRspSysId(AppParamConstant.SYS_ID);
            bizResponse.setRespCode(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode());
            bizResponse.setRespDesc(RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
            return bizResponse;
        }

        response.setMsg("id不存在，请求错误");
        bizResponse.setResult(response);
        bizResponse.setRspSysId(AppParamConstant.SYS_ID);
        bizResponse.setRespCode(RespCodeEnum.MCHNT_INST_IS_NULL.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.MCHNT_INST_IS_NULL.getRespDesc());
        return bizResponse;
    }

    @Override
    protected void bizAfterCust(Object response) throws Exception {

    }
}
